package dao

import (
	"errors"
	"gorm.io/gorm"
)

type UserService struct {
	repo IUserRepo
	db   *gorm.DB
}

func NewUserService(repo IUserRepo) *UserService {
	return &UserService{repo: repo}
}

func (u *UserService) Find(id int) (*User, error) {
	user := u.repo.GetUserById(id)
	if user == nil {
		return nil, errors.New("user not found")
	}
	return user, nil
}

func (u *UserService) Create(user *User) error {
	return u.repo.CreateUser(user)
}
